package com.atguigu.day16.math01;

import org.junit.Test;

import java.math.BigDecimal;
import java.math.RoundingMode;

/*
BigDecimal: 更加精确的小数
        结果是无限小数: 1.保留的小数位数
                      2.舍入模式

 */
public class BigDecimalTest {
    @Test
    public void test03() {
        BigDecimal b1 = new BigDecimal("10");
        BigDecimal b2 = new BigDecimal("3");

       // BigDecimal divide = b1.divide(b2);
        BigDecimal divide = b1.divide(b2, 10, RoundingMode.FLOOR);
        System.out.println("divide = " + divide);
    }


    @Test
    public void test02() {
        BigDecimal b1 = new BigDecimal("10.0");
        BigDecimal b2 = new BigDecimal("4.0");
        System.out.println("b1.add(b2) = " + b1.add(b2));
        System.out.println("b1.subtract(b2) = " + b1.subtract(b2));
        System.out.println("b1.multiply(b2) = " + b1.multiply(b2));
        System.out.println("b1.divide(b2) = " + b1.divide(b2));
        System.out.println("b1.remainder(b2) = " + b1.remainder(b2));
    }


    @Test
    public void test01() {

        double d = 3.3333333333333333333;

        System.out.println("d = " + d);

        System.out.println(0.1 + 0.2);

        BigDecimal b1 = new BigDecimal("3.3333333333333333333");
        System.out.println("b1 = " + b1);

    }
}
